﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sinacor.OMM.HealthMonitor.Entity.Msmq;
using Sinacor.OMM.HealthMonitor.Entity.Common;

namespace Sinacor.OMM.HealthMonitor.Entity.Receiver
{
    [Serializable()]
    public class MSMQConnection : IHealthDataReset
    {

        private HealthEntityBase _healthEntityBase;
        public MSMQConnection()
        {
            _healthEntityBase = new HealthEntityBase();
        }

        public MSMQConnection(HealthEntityBase healthEntityBase)
        {
            _healthEntityBase = healthEntityBase;
            _receiverQueue = new MsmqData(_healthEntityBase);
        }

        //Número de Tentativas Reconexão com MSMQ (Fila router)
        long _receiverQueueConnectionsReTries;
        public long ReceiverQueueConnectionsReTries
        {
            get { return _receiverQueueConnectionsReTries; }
            set 
            { 
                _receiverQueueConnectionsReTries = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        //Número de Tentativas Reconexão com MSMQ (Fila dump)
        long _dumpQueueConnectionsReTries;
        public long DumpQueueConnectionsReTries
        {
            get { return _dumpQueueConnectionsReTries; }
            set 
            { 
                _dumpQueueConnectionsReTries = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        private MsmqData _receiverQueue;
        public MsmqData ReceiverQueue
        {
            get { return _receiverQueue; }
            set 
            { 
                _receiverQueue = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }


        //Receptor parado ao exceder limite de alguma fila MSMQ
        bool _receiverStoppedByQueueLimitReached;
        public bool ReceiverStoppedByQueueLimitReached
        {
            get { return _receiverStoppedByQueueLimitReached; }
            set 
            {
               _receiverStoppedByQueueLimitReached = value;
               _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        bool _goodStateReceiverStoppedByQueueLimitReached;
        public bool GoodStateReceiverStoppedByQueueLimitReached
        {
            get { return _goodStateReceiverStoppedByQueueLimitReached; }
            set 
            { 
                _goodStateReceiverStoppedByQueueLimitReached = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        public void Reset()
        {
            ReceiverQueueConnectionsReTries = 0;
            DumpQueueConnectionsReTries = 0;
            ReceiverStoppedByQueueLimitReached = false;
            ReceiverQueue = new MsmqData(_healthEntityBase);
        }
    }
}
